﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:clr="clr-namespace:System;assembly=mscorlib" xmlns:local="clr-namespace:PropertyTools.Wpf" xmlns:Collections="clr-namespace:System.Collections;assembly=mscorlib" xmlns:h="clr-namespace:PropertyTools.Wpf.Helpers">

    <!-- CLR & Custom Types Data Templates -->

    <DataTemplate x:Key="DefaultTemplate">
        <TextBox 
            IsReadOnly="{Binding IsReadOnly}" 
            IsEnabled="{Binding IsEnabled}" 
            MaxLength="{Binding MaxLength}"
            Text="{Binding Value, ValidatesOnDataErrors=True}" 
            AcceptsReturn="{Binding AcceptsReturn}" 
            TextWrapping="{Binding TextWrapping}" 
            VerticalScrollBarVisibility="Auto" 
            Height="{Binding Height}">
        </TextBox>
        <!--<local:TextBoxEx 
            IsReadOnly="{Binding IsReadOnly}" 
            IsEnabled="{Binding IsEnabled}" 
            Text="{Binding Value, ValidatesOnDataErrors=True}" 
            AcceptsReturn="{Binding AcceptsReturn}" 
            TextWrapping="{Binding TextWrapping}" 
            VerticalScrollBarVisibility="Auto" 
            Height="{Binding Height}">
        </local:TextBoxEx>-->
        <!--<local:FormattingTextBox 
            IsReadOnly="{Binding IsReadOnly}" 
            IsEnabled="{Binding IsEnabled}" 
            MaxLength="{Binding MaxLength}"
            Value="{Binding Value, ValidatesOnDataErrors=True}" 
            AcceptsReturn="{Binding AcceptsReturn}" 
            Height="{Binding Height}"
            TextWrapping="{Binding TextWrapping}" 
            VerticalScrollBarVisibility="Auto" 
            StringFormat="{Binding FormatString}"/>-->
    </DataTemplate>

    <DataTemplate x:Key="DefaultTemplateAutoUpdate">
        <TextBox 
            IsReadOnly="{Binding IsReadOnly}" 
            IsEnabled="{Binding IsEnabled}" 
            Text="{Binding Value, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}" 
            AcceptsReturn="{Binding AcceptsReturn}" 
            TextWrapping="{Binding TextWrapping}" 
            VerticalScrollBarVisibility="Auto" 
            Height="{Binding Height}">
        </TextBox>
    </DataTemplate>

    <local:ToDoubleConverter x:Key="ToDoubleConverter"/>
    <local:EnumValuesConverter x:Key="EnumValuesConverter"/>
    <local:EnumDescriptionConverter x:Key="EnumDescriptionConverter"/>

    <DataTemplate x:Key="SliderBoxTemplate">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="1*" />
                <ColumnDefinition Width="1*" />
            </Grid.ColumnDefinitions>
            <Slider 
                Maximum="{Binding SliderMaximum}" 
                Minimum="{Binding SliderMinimum}" 
                SmallChange="{Binding SliderSmallChange}" 
                LargeChange="{Binding SliderLargeChange}" 
                IsSnapToTickEnabled="{Binding SliderSnapToTicks}" 
                TickFrequency="{Binding SliderTickFrequency}"
                TickPlacement="{Binding SliderTickPlacement}"
                IsEnabled="{Binding IsEnabled}" Focusable="True" Margin="0 0 4 0"
                Value="{Binding Value, Mode=TwoWay, Converter={StaticResource ToDoubleConverter}}" 
                VerticalAlignment="Center" />
            <local:FormattingTextBox 
                Grid.Column="1" 
                IsReadOnly="{Binding IsReadOnly}" 
                IsEnabled="{Binding IsEnabled}" 
                Value="{Binding Value, ValidatesOnDataErrors=True}" 
                StringFormat="{Binding FormatString}"/>
        </Grid>
    </DataTemplate>

    <!-- bool -->
    <DataTemplate x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyEditor}, ResourceId={x:Type clr:Boolean}}">
        <CheckBox IsEnabled="{Binding IsWriteable}" IsChecked="{Binding Value, ValidatesOnDataErrors=True}" HorizontalAlignment="Left" VerticalAlignment="Center" />
    </DataTemplate>

    <!-- list -->
    <DataTemplate x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyEditor}, ResourceId={x:Type Collections:IList}}">
        <ListBox ItemsSource="{Binding Value}" />
    </DataTemplate>

    <!-- enum -->
    <DataTemplate x:Key="ComboBoxEnumTemplate">
        <ComboBox SelectedValue="{Binding Value}" IsEnabled="{Binding IsWriteable}" ItemsSource="{Binding Value, Converter={StaticResource EnumValuesConverter}}">
            <ComboBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Converter={StaticResource EnumDescriptionConverter}}"/>
                </DataTemplate>
            </ComboBox.ItemTemplate>
        </ComboBox>
    </DataTemplate>

    <DataTemplate x:Key="RadioButtonsEnumTemplate">
        <local:RadioButtonList Value="{Binding Value}" />
    </DataTemplate>

    <DataTemplate x:Key="FilePathTemplate">
        <local:FilePicker FilePath="{Binding Value, ValidatesOnDataErrors=True}" Filter="{Binding Filter}" DefaultExtension="{Binding DefaultExtension}"
                          FileDialogService="{Binding FileDialogService}" UseOpenDialog="{Binding UseOpenDialog}"/>
    </DataTemplate>

    <DataTemplate x:Key="DirectoryPathTemplate">
        <local:DirectoryPicker Directory="{Binding Value, ValidatesOnDataErrors=True}" FolderBrowserDialogService="{Binding FolderBrowserDialogService}"/>
    </DataTemplate>

    <DataTemplate x:Key="PasswordTemplate">
        <PasswordBox IsEnabled="{Binding IsEnabled}"
                     h:PasswordHelper.Attach="True" h:PasswordHelper.Password="{Binding Value, Mode=TwoWay}">
        </PasswordBox>
    </DataTemplate>

</ResourceDictionary>